﻿<%@ Page Title="Quản lý quảng cáo" Language="C#" MasterPageFile="~/Administrator/MasterPage.master"
    AutoEventWireup="true" CodeFile="advertiseposition.aspx.cs" Inherits="Administrator_advertiseposition" %>

<%@ Register Assembly="CollectionPager" Namespace="SiteUtils" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        .cate option
        {
            padding: 0px;
            margin-left: 5px;
        }
    </style>
    <script type="text/javascript">

        function checknumber(e, id) {
            var key;
            var list = id.split('a');

            var a = document.getElementById("txtSortDisplay" + id);
            if (window.event)
                key = window.event.keyCode;     //IE 
            else
                key = e.which;     //firefox 
            if (key == 13) {
                if (isNaN(a.value)) {
                    alert("Thứ tự hiển thị phải là số!");
                    return;
                }
                $.ajax({
                    type: "POST",
                    url: "../service/hentocdo.asmx/UpdatePositionStatus",
                    data: "{'aid':'" + list[0] + "','pid':'" + list[1] + "','index':'" + a.value + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",

                    success: function (message) {
                        if (message.d == false) {
                            $("div.message").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                        }
                    }
                });
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="content">
        <script type="text/javascript">
            var index = "";
            $(document).ready(function () {
                $("input.add").click(function () {
                    window.location.href = "advertiseadd.aspx";
                });
                $("input.del").click(function () {
                    $("table input[type=checkbox].item").each(function () {
                        var checked = $(this).attr("checked");
                        if (checked) {
                            index = index + $(this).attr("value") + ";";
                        }
                    });
                    $("#<%=hdfCheck.ClientID%>").val(index);
                    if (index == "") return false;
                    else return confirm("Xác nhận xóa !");
                });

                $("input[title=Display]").click(function () {

                    var input = $(this);
                    $.ajax({
                        type: "POST",
                        url: "../service/hentocdo.asmx/Display_Position",
                        data: "{'aid':'" + $(this).parent().parent().attr("id") + "','pid':'" + $(this).parent().attr("id") + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        beforeSend: function () {
                            $("div.message").html("");
                        },
                        success: function (message) {
                            if (message.d == false) {
                                $("div.message").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                            }
                            else {
                                if ($(input).hasClass("True")) {
                                    $(input).removeClass("True");
                                    $(input).addClass("False");
                                }
                                else {
                                    $(input).removeClass("False");
                                    $(input).addClass("True");
                                }
                                $("div.message").html("<div id='message-success' class='message message-success'><div class='image'><img src='../resources/images/icons/success.png' alt='Success' height='32' /></div><div class='text'><h6>Thông Báo</h6><span>Cập nhật thành công !</span></div><div class='dismiss'><a href='#message-success'></a></div></div>");
                            }
                        },
                        error: function (errormessage) {
                            $("div.message").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                        }
                    });
                });
            });
        </script>
        <asp:HiddenField ID="hdfCheck" runat="server" />
        <div class="box">
            <!-- box / title -->
            <div class="title" style="background-color: #3B5998">
                <h5 id="txtTitle">
                    Danh sách sự kiện
                </h5>
                <div class="search" style="padding-top: 6px; padding-bottom: 4px;">
                    <div class="input">
                        <asp:DropDownList ID="ddlType" runat="server" Width="220px" AutoPostBack="True" CssClass="cate"
                            OnSelectedIndexChanged="ddlType_SelectedIndexChanged">
                            <asp:ListItem Value="-1">-- Vị trí quảng cáo --</asp:ListItem>
                            <asp:ListItem Value="1">Trang chủ</asp:ListItem>
                            <asp:ListItem Value="2">Bí quyết</asp:ListItem>
                            <asp:ListItem Value="3">Tin tức</asp:ListItem>
                            <asp:ListItem Value="4">Chi tiết bài tin</asp:ListItem>
                            <asp:ListItem Value="5">Hỏi đáp</asp:ListItem>
                            <asp:ListItem Value="6">Giới thiệu</asp:ListItem>
                            <asp:ListItem Value="7">Quy định</asp:ListItem>
                        </asp:DropDownList>
                    </div>
                </div>
            </div>
            <div id="divMessage" runat="server">
            </div>
            <div class="first-action">
                <div class="button">
                    <asp:Button role="button" ID="btnDelete" Text="Xóa" class="del ui-button ui-widget ui-state-default ui-corner-all"
                        runat="server" OnClick="btnDelete_Click" />
                    <br>
                </div>
            </div>
            <!-- end box / title -->
            <div class="table">
                <table>
                    <thead>
                        <tr>
                            <th class="stt">
                                STT
                            </th>
                            <th>
                                Mô tả
                            </th>
                            <th>
                                Ảnh
                            </th>
                            <th>
                                Thời gian bắt đầu
                            </th>
                            <th>
                                Thời gian kết thúc
                            </th>
                            <th>
                                Link url
                            </th>
                            <th>
                                Thứ tự
                            </th>
                            <th>
                                Trạng thái
                            </th>
                            <th class="edit">
                                Sửa
                            </th>
                            <th class="selected last">
                                <input class="checkall" type="checkbox" />
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater runat="server" ID="rptData" 
                            onitemdatabound="rptData_ItemDataBound">
                            <ItemTemplate>
                                <tr id='<%# Eval("advertise_id")%>'>
                                    <td align="center" style="vertical-align: middle">
                                        <%#Container.ItemIndex+1 %>
                                    </td>
                                    <td valign="middle">
                                        <a title='<%# Eval("TITLE")%>' href='<%#"advertiseedit.aspx?advertise_id="+Eval("advertise_id")%>'>
                                            <%#Eval("TITLE")%>
                                        </a>
                                    </td>
                                    <td valign="middle" align="center">
                                        <a style="cursor: pointer" class="screenshot" rel="../imgadvertise/<%# Eval("PICTURE")%>">
                                            <div id="p1" runat="server">
                                                <a style="cursor: pointer" class="screenshot" rel="../imgadvertise/<%# Eval("PICTURE")%>">
                                                    <img alt="" src="../imgadvertise/<%# Eval("PICTURE")%>" width="70px" height="70px" />
                                                </a>
                                            </div>
                                            <div id="p2" runat="server" visible="false">
                                                <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
                                                    id="mymoviename">
                                                    <param name="movie" value="../imgadvertise/<%# Eval("PICTURE")%>" />
                                                    <param name="quality" value="high" />
                                                    <param name="bgcolor" value="#ffffff" />
                                                    <embed src="../imgadvertise/<%# Eval("PICTURE")%>" quality="high" bgcolor="#ffffff"
                                                        width="100px" name="mymoviename" align="" type="application/x-shockwave-flash"
                                                        pluginspage="http://www.macromedia.com/go/getflashplayer">'
                                                    </embed></object>
                                            </div>
                                        </a>
                                    </td>
                                    <td valign="middle" align="center">
                                        <%# string.Format("{0:dd/MM/yyyy}", DateTime.Parse(Eval("STARTDATE").ToString()))%>
                                    </td>
                                    <td valign="middle" align="center">
                                        <%# string.Format("{0:dd/MM/yyyy}", DateTime.Parse(Eval("ENDDATE").ToString()))%>
                                    </td>
                                    <td valign="middle" align="center">
                                        <%#Eval("LINKURL")%>
                                    </td>
                                    <td valign="middle" align="center">
                                        <input id='txtSortDisplay<%#Eval("ADVERTISE_ID") %>a<%#Eval("POSITION_ID") %>' type="text"
                                            value='<%#Eval("SORTDISPLAY")%>' class="number" style="width: 20px; text-align: center;
                                            border: 1px solid #3B5998" onkeypress="checknumber(event,'<%#Eval("ADVERTISE_ID") %>a<%#Eval("POSITION_ID") %>')" />
                                    </td>
                                    <td valign="middle" align="center" id='<%# Eval("position_id")%>'>
                                        <input type="button" title="Display" class='<%#(Eval("STATUS").ToString() == "1"? "True" : "False") %>' />
                                    </td>
                                    <td align="center">
                                        <a title="Chỉnh Sửa" href='<%#"advertiseedit.aspx?advertise_id="+Eval("advertise_id")%>'>
                                            <img src="../images/edit.png" class="icon-32-edit" alt="" />
                                        </a>
                                    </td>
                                    <td align="center" class="last">
                                        <input type="checkbox" value="<%#Eval("advertise_id")%>" class="item" />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
                <div class="pagination pagination-left last">
                    <div id="pagerContainer" class="pagerContainer">
                        <cc1:CollectionPager ID="CollectionPager1" runat="server" MaxPages="50">
                        </cc1:CollectionPager>
                    </div>
                </div>
                <div class="action">
                    <div class="button">
                        <asp:Button role="button" ID="btnDelete2" Text="Xóa" class="del ui-button ui-widget ui-state-default ui-corner-all"
                            runat="server" OnClick="btnDelete2_Click" />
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- end table -->
</asp:Content>
